package TestExercises02;

public class GirlFriendsTest {
    public static void main(String[] args) {
        //1、创建一个数组
        GirlFriends[] arr = new GirlFriends[4];

        //2、创建女朋友们对象
        GirlFriends gf1 = new GirlFriends("小诗诗", 18, "萌妹子", "吃零食");
        GirlFriends gf2 = new GirlFriends("小丹丹", 19, "萌妹子", "玩游戏");
        GirlFriends gf3 = new GirlFriends("小慧慧", 20, "萌妹子", "看书，学习");
        GirlFriends gf4 = new GirlFriends("小莉莉", 21, "憨妹子", "睡觉");

        //3、将对象添加到数组当中
        arr[0] = gf1;
        arr[1] = gf2;
        arr[2] = gf3;
        arr[3] = gf4;

        //4、求平均年龄
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriends gf = arr[i];
            sum = sum + gf.getAge();
        }
        int avg = sum / arr.length;
        System.out.println("女朋友们的平均年龄为：" + avg);

        //5、统计
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getAge() < avg) {
                count++;
                System.out.println(arr[i].getName() + ", " + arr[i].getAge() + ", " + arr[i].getGender() + ", " + arr[i].getHobby());
            }
        }
        System.out.println("有" + count + "个比平均年龄的低的女朋友");
    }
}
